//this is js document

var articleOption = {
		'articleName':{
			'param':{'id':"title",'onclick':articleRedirect},
			'bind':{'targetId':"articleId",'userName':"userName"}
		},
		'publishTime':{
			'param':{'id':"publishTime"}
		},
		'replyTimes':{
			'style':{'color': 'red'},
			'param':{'id':"replyTimes"}
		}
	}
var dongtaiOption = {
		'articleName':{
			'param':{'id':"title",'onclick':dongtaiRedirect},
			'bind':{'targetId':"userId",'userName':"userName"}
		},
		'publishTime':{
			'param':{'id':"publishTime"}
		},
		'replyTimes':{
			'style':{'color': 'red'},
			'param':{'id':"replyTimes"}
		}
	}

window.onload = function(){
	//登录页面后通过myajax获取进一步的信息
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/forum/welcome_all_data.do?index=0&size=10",welcomeCallBack);
	myajax = null;
}
window.alert = function(content){
	var alpha = document.createElement("section");
	alpha.className = "alpha8 alert";
	
	document.body.appendChild(alpha);
	
	var notice = document.createElement("section");
	notice.className = "notice";
	notice.innerHTML = content;
	
	document.body.appendChild(notice);
	
	setTimeout(function(){
		document.body.removeChild(alpha);
		document.body.removeChild(notice);
	}, 2000);
}
function welcomeCallBack(d){
//	var data = eval("("+d+")");
	var data = toJson(d);
	var article = data.article;
	var notice = data.notice;
	var dongtai = data.dongtai;
	
	page.view('articleInner',article,articleOption);
	page.view('activeInner',dongtai,dongtaiOption);
	
	var isLogin = data.isLogin;
	if(isLogin){
		document.getElementById("login").style.display = "none";
	}
	
	var myajax = getByAjax();
	myajax.init(null,"get",true);
	myajax.get("/networkforum/forum/welcome_hot_data.do?index=0&size=10",hotCallBack);
	myajax = null;
}
function hotCallBack(d){
//	var data = eval("("+d+")");
	var data = toJson(d);
	var hotUser = data.hotUser;
	var hotArticle = data.hotArticle;
	var fishUser = data.fishUser;
	var hotPicture = data.hotPicture;
	var userOption = {'userName':{'style':{'color': 'red'},'param':{'id':"userName"}		
			},'userPhoto':{'param':{'id':"userPhoto"},'bind':{'module':"user",
				'targetId':'userId','title':'userSex'}}}
	var articleOption = {
			'userName':{
				'param':{'id':"hauserName"},
				'bind':{'articleId':"articleId"}
			},
			'articleName':{
				'param':{'id':"hacontent"}
			}
		}
	var fishOption = {'userPhoto':{'param':{'id':"userPhoto"},'bind':{
		'targetId':'userId','module':"user",'title':'userName'}},'userName':{'param':{
			'id':"userNameli"}},'userSex':{'style':{'color': 'red'},'param':{'id':"userSex"}}}
	var pictureOption = {
			'pictureSrc':{
				'param':{'id':"hpinner"},
				'bind':{'targetId':'pictureId','module':"picture",'title':'uploadTime',
					'onmouseover':over,'onmouseout':out}
			}
		}
	//page.view.methods.reloadPicture(true);
	page.view('hotUserInner',hotUser,userOption,true);
	page.view('hotArticleInner',hotArticle,articleOption,true);
	page.view('fishInner',fishUser,fishOption,true);
	page.view('pgmain',hotPicture,pictureOption,true);
	var pgmain = document.getElementById('pgmain');
	pgmain.removeChild(pgmain.children[0]);
	//http://qxlove.vicp.net:8010/user/userPicture/xunxun/ceshi/image201102010002_3.jpg
	//绑定图片点击事件
	var images = document.getElementsByTagName("img");
	for(var i =0;i<images.length;i++){
		if(images[i].targetId){
			BindOnclickEvent(images[i]);
		}
	}
}
function articleRedirect(event){
	event = event || window.event;
	var target = event.target || event.srcElement;
	var targetId = target.targetId;
	var userName = target.userName;
	
	location = "/networkforum/article/article_main.do?articleId="+targetId+"&userName="+userName;
}
function dongtaiRedirect(event){
	event = event || window.event;
	var target = event.target || event.srcElement;
	location = "/networkforum/visit/visit_user.do?targetId="+target.targetId;
}














